package uit.shoeshop.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

import uit.shoeshop.dto.CategoryDTO;
import uit.shoeshop.model.SidebarModel;
import java.util.ArrayList;
import java.util.HashMap;

public class SidebarAction extends ActionSupport implements ServletRequestAware,ServletResponseAware{
	private static final long serialVersionUID = 1L;
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	private ArrayList<CategoryDTO> parentCate;
	private HashMap<Integer, ArrayList<CategoryDTO>> childCate;

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	
    public String execute() throws Exception {
    	SidebarModel sidebar = new SidebarModel();
    	try{
    		setParentCate(sidebar.getAllParentCategory());
    		setChildCate(sidebar.getAllChildCategory(getParentCate()));
    	}catch(Exception e){
    		return ERROR;
    	}finally{
    		sidebar = null;
    	}
        return SUCCESS;
    }

	/**
	 * @param parentCate the parentCate to set
	 */
	public void setParentCate(ArrayList<CategoryDTO> parentCate) {
		this.parentCate = parentCate;
	}

	/**
	 * @return the parentCate
	 */
	public ArrayList<CategoryDTO> getParentCate() {
		return parentCate;
	}

	/**
	 * @param childCate the childCate to set
	 */
	public void setChildCate(HashMap<Integer, ArrayList<CategoryDTO>> childCate) {
		this.childCate = childCate;
	}

	/**
	 * @return the childCate
	 */
	public HashMap<Integer, ArrayList<CategoryDTO>> getChildCate() {
		return childCate;
	}
}
